package org.traffometer.traffobase.webapp.control.command;

import org.traffometer.traffobase.model.PacketStore;
import org.traffometer.traffobase.webapp.control.Page;
import javax.servlet.http.HttpServletRequest;

/**
 * Implements the "ShowMap" command which shows the location where the 
 * TraffoPacket was sent on Google Map.
 *
 * @author Kiet Huynh
 */
public class ShowMapCommand implements Command {

  /**
   * Processes the "ShowMap" command sent by the user.
   * Sets the packetStoreIterator attribute with the current packetStore contents.
   *
   * @param request The request object.
   * @param packetStore The packet store.
   * @return The page to be displayed (Page.MAP).
   */
  public Page process(HttpServletRequest request, PacketStore packetStore) {
    request.setAttribute("packetStoreIterator", packetStore.iterator());
    int index = Integer.parseInt(request.getParameter("number"));
    request.setAttribute("latitude1", packetStore.getPackets().get(index).getLatitude1());
    request.setAttribute("latitude1", packetStore.getPackets().get(index).getLatitude2());
    request.setAttribute("longitude1", packetStore.getPackets().get(index).getLongitude1());
    request.setAttribute("longitude2", packetStore.getPackets().get(index).getLongitude2());
    return Page.MAP;
  }
}
